//--------------------------------------------------------------------------------
// This file is a portion of the D2D1Renderer.  It is distributed
// under the MIT License, available in the root of this distribution and 
// at the following URL:
//
// http://www.opensource.org/licenses/mit-license.php
//
// Copyright (c) Mirco Timmermann
//
//--------------------------------------------------------------------------------
/*
* Aufbau: "Container(this)" -> [ "Container" -> [ "displayObject"* ], "ScrollBar" ]
* HACK 001 -> (delegation of scrollBar mouseDrag) override scrollBar mouseDrag function for subsequenz.
* HACK 002 -> (clipping of the container) Cuts the elements inside the container.
*/

/*
|------------------|---|  this(container) childs-> [this._fixedContainer, this._scrollBar];
|                  | S |  this._fixedContainer childs-> [this.container];
|                  | c |  this.container <- moveable with the scrollbar;
|                  | r |  fixedContainer <- mouseAvoidingEnabled = true;
|  fixedContainer  | o |
|                  | l |
|                  | l |
|                  | B |
|                  | a |
|                  | r |
|------------------|---|
*/
#pragma once

#include "..\..\DisplayObjectContainer.h"
#include "..\ScrollBar.h"


namespace D2 {

class ScrollBarContainer : public DisplayObjectContainer {
public:
	enum ScrollBarType {
		VERTICAL, 
		HORIZONTAL
	};

public:
	ScrollBarContainer(int x, int y, int width, int height, ScrollBarType type);
	virtual ~ScrollBarContainer(void);

	virtual bool Draw(Direct2DContext* ctx, D2D1::Matrix3x2F* mtx = 0);

private:
	bool _autoResizeX;
	bool _autoResizeY;

	int _totalWidth;
	int _totalHeight;

private:
	void ON_MOUSE_DRAG0_scrollBar(const Event &event);

	void Update(DisplayObject* child);
	void Refresh();
	void UpdatePosition();

	void Draw_background(Direct2DContext* ctx);

private:
	ScrollBarType _type;

	DisplayObjectContainer* _fixedContainer;
	DisplayObjectContainer* _contentContainer;

protected:
	ScrollBar* _scrollBar;

public:
	virtual DisplayObject* addChild(DisplayObject* displayObject);
	virtual void removeAllChildren(bool recursive = false, bool del = false);

protected:
	bool _autoAlignX;
	bool _autoAlignY;

	bool _autoSortY;

public:
	virtual void EnableAutoAlignX(bool enable);
	virtual void EnableAutoAlignY(bool enable);

private:
	void alignContainerByY(bool sort = false);

};

}